package com.edocbase.desktopserver.util;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;

public class FileUtils {
	public static String readFileAsString(String fileName,String charsetName) throws Exception {
		String content = new String(readBytes(fileName),charsetName);

		return content;
	}
	public static byte[] readBytes(String fileName) throws Exception {
		byte buf[] = new byte[1024];
		FileInputStream fin = new FileInputStream(fileName);
		BufferedInputStream in = new BufferedInputStream(fin);

		ByteArrayOutputStream out = new ByteArrayOutputStream(10240);

		int len;
		while ((len = in.read(buf)) >= 0)
			out.write(buf, 0, len);
		in.close();

		return out.toByteArray();
	}
}
